// -----------------------------
// Author: 		Dhaenens Gert 
// Creation: 	9/17/2014 9:52:19 AM				
// -----------------------------

#ifndef _LuaDataMember_h
#define _LuaDataMember_h

#include "ObjectLuaCommon.h"
#include "Lua.h"

namespace ObjectLua
{

	template<typename Class>
	class LuaDataList;

	template<typename Class>
	class BaseLuaDataMember
	{
	public:
		friend class LuaDataList<Class>;

		virtual void	setValue(Lua* lpLua, Class* lpObject, int idx) = 0;
		virtual void	getValue(Lua* lpLua, Class* lpObject) = 0;

		bool			isReadOnly() const;

	protected:
		BaseLuaDataMember(const char* name, bool bReadOnly);
		virtual ~BaseLuaDataMember();

		char*						m_lpName;
		bool						m_bReadOnly;
		BaseLuaDataMember<Class>*	m_lpNext;

	private:
		BaseLuaDataMember(const BaseLuaDataMember& refBaseLuaDataMember);
		BaseLuaDataMember& operator=(const BaseLuaDataMember& refBaseLuaDataMember);
	};

	template<typename Class, typename T>
	class LuaDataMember : public BaseLuaDataMember<Class>
	{
	public:
		typedef T Class::*DataMember;

		LuaDataMember(const char* name, DataMember member, bool bReadOnly);
		virtual ~LuaDataMember();

		virtual void	setValue(Lua* lpLua, Class* lpObject, int idx);
		virtual void	getValue(Lua* lpLua, Class* lpObject);

	private:

		DataMember		m_Member;

		LuaDataMember(const LuaDataMember& refLuaDataMember);
		LuaDataMember& operator=(const LuaDataMember& refLuaDataMember);
	};

	template<typename Class, typename T>
	class LuaDataMember<Class, const T> : public BaseLuaDataMember<Class>
	{
	public:
		typedef const T Class::*DataMember;

		LuaDataMember(const char* name, DataMember member, bool bReadOnly);
		virtual ~LuaDataMember();

		virtual void	setValue(Lua* lpLua, Class* lpObject, int idx);
		virtual void	getValue(Lua* lpLua, Class* lpObject);

	private:

		DataMember		m_Member;

		LuaDataMember(const LuaDataMember& refLuaDataMember);
		LuaDataMember& operator=(const LuaDataMember& refLuaDataMember);
	};

}

#include "LuaDataMember.inl"
#endif